Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
symbol-observable
Advanced tools
The symbol-observable package is primarily used to polyfill the Observable symbol, which is a proposed addition to the ECMAScript standard. It allows JavaScript objects to be observable, meaning that other objects can subscribe to them and react to changes. This is particularly useful in reactive programming models and libraries, such as RxJS, where data streams and their transformations are a core concept.
Polyfill for Observable Symbol
This code demonstrates how to use the symbol-observable package to make an object observable. It defines a simple observable that emits 'hi' every second. An observer subscribes to this observable to log the emitted values. This showcases how symbol-observable can be used to implement the observer pattern in JavaScript.
"use strict";
const symbolObservable = require('symbol-observable').default;
console.log(typeof symbolObservable); // 'symbol' in environments with native Symbol support
const obj = {};
obj[symbolObservable] = function () {
return {
subscribe(observer) {
const intervalID = setInterval(() => observer.next('hi'), 1000);
return {
unsubscribe() {
clearInterval(intervalID);
}
};
}
};
};
const observable = obj[symbolObservable]();
const subscription = observable.subscribe({
next(val) { console.log(val); },
complete() { console.log('Done'); }
});
// Later:
// subscription.unsubscribe();
RxJS is a library for reactive programming using Observables, to make it easier to compose asynchronous or callback-based code. Unlike symbol-observable, which provides the basic polyfill for the Observable symbol, RxJS offers a comprehensive suite of operators for transforming, combining, and managing asynchronous streams of data.
Zen Observable is a lightweight implementation of Observables for JavaScript. It provides an Observable class that can be used directly, without needing a polyfill. Compared to symbol-observable, Zen Observable offers more out-of-the-box functionality, including a full implementation of the Observable spec, rather than just providing the symbol.
Symbol.observable ponyfill
$ npm install --save symbol-observable
const symbolObservable = require('symbol-observable');
console.log(symbolObservable);
//=> Symbol(observable)
MIT © Sindre Sorhus
FAQs
Symbol.observable ponyfill
The npm package symbol-observable receives a total of 2,607,826 weekly downloads. As such, symbol-observable popularity was classified as popular.
We found that symbol-observable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.